/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package frontera;

import DAOs.DaoPerson;
import control.crudMovie;
import control.crudPerson;
import entidad.Actor;
import entidad.Director;
import entidad.Movie;
import java.io.File;
import java.util.ArrayList;
import java.util.Date;


/**
 *
 * @author Stiv
 */
public class BuscadorPrincipal extends javax.swing.JFrame {
    
    
    private Busqueda busqueda = new Busqueda();

    /**
     * Creates new form BuscadorPrincipal
     */
    public BuscadorPrincipal() {
        initComponents();
        inicializar();
        baseDatos();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSeparator1 = new javax.swing.JSeparator();
        buscarTF = new javax.swing.JTextField();
        buscarBT = new javax.swing.JButton();
        PanelP = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        buscarTF.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        buscarTF.setText("Buscar Pelicula (Probar con buscador de abajo, este falla a veces)");
        buscarTF.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                buscarTFMouseReleased(evt);
            }
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                buscarTFMouseClicked(evt);
            }
        });
        buscarTF.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                buscarTFKeyReleased(evt);
            }
        });

        buscarBT.setIcon(new javax.swing.ImageIcon(getClass().getResource("/frontera/imagenes/iconoBuscar.jpg"))); // NOI18N

        PanelP.setLayout(new java.awt.BorderLayout());
        PanelP.add(jLabel1, java.awt.BorderLayout.CENTER);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(PanelP, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(35, 35, 35)
                                .addComponent(buscarTF, javax.swing.GroupLayout.PREFERRED_SIZE, 453, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(30, 30, 30))
                            .addComponent(jSeparator1))
                        .addGap(2, 2, 2)
                        .addComponent(buscarBT, javax.swing.GroupLayout.PREFERRED_SIZE, 44, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(50, 50, 50)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(buscarTF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(buscarBT, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(PanelP, javax.swing.GroupLayout.DEFAULT_SIZE, 451, Short.MAX_VALUE)
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void buscarTFMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buscarTFMouseClicked
        buscarTF.setText("");
    }//GEN-LAST:event_buscarTFMouseClicked

    private void buscarTFMouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_buscarTFMouseReleased

    }//GEN-LAST:event_buscarTFMouseReleased

    private void buscarTFKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_buscarTFKeyReleased
        // TODO add your handling code here:
        
        
        if(!(busqueda.isShowing())){
            PanelP.removeAll();
            PanelP.add(busqueda);
            busqueda.setVisible(true);
            busqueda.inicializar();
        }
        
        busqueda.dlmlista.clear();
        
        ArrayList<Movie> peliculas = new ArrayList();
        peliculas = crudMovie.TraerPeliculas(buscarTF.getText());
        for(Movie c: peliculas){
        busqueda.dlmlista.addElement(c.getNombre());
        
        }
    }//GEN-LAST:event_buscarTFKeyReleased

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(BuscadorPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(BuscadorPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(BuscadorPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(BuscadorPrincipal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new BuscadorPrincipal().setVisible(true);
            }
        });
    }
    
    public void inicializar(){
        this.setName("General Store - Look Up");
        this.setSize(660, 668);
        PanelP.add(busqueda);
        busqueda.setVisible(true);
        busqueda.inicializar();
        
    };
    
    public void baseDatos(){
        
        
        
        crudPerson.crearDirector("Clint","Eastwood",new File ("./src/frontera/imagenes/eastwood.jpg"),"13/05/1930","California, EEUU",100);
        crudPerson.crearDirector("Juan Jose", "Campanella", new File ("./src/frontera/imagenes/campanella.jpg"), "19/07/1959", "Buenos Aires, Argentina", 101);
        crudPerson.crearDirector("Joss", "Whedon", new File("./src/frontera/imagenes/whedon.jpg"), "23/051964", "New York, EE.UU", 102);
        crudPerson.crearActor("Clint","Eastwood",new File ("./src/frontera/imagenes/eastwood.jpg"),"13/05/1930","California, EEUU",200);
        crudPerson.crearActor("Ricardo","Darín", new File("./src/frontera/imagenes/darin.jpg"),"16/01/1957","Buenos Aires, Argentina",201);
        crudPerson.crearActor("Bee", "Vang", null, "04/11/1991", "California EE.UU", 202);
        crudPerson.crearActor("Soledad", "Villamil", new File("./src/frontera/imagenes/soledad.jpg"), "19/06/1969", "Buenos Aires, Argentina", 203);
        crudPerson.crearActor("Robert", "Downey Jr", new File("./src/frontera/imagenes/downey.jpg"), "04/04/1965", "New York, EE.UU", 204);
        crudPerson.crearActor("Chris", "Evans", new File("./src/frontera/imagenes/evans.jpg"), "13/06/1981", "Massachusetts, EE.UU", 205);
        crudPerson.crearActor("Scarlett", "Johansson", new File("./src/frontera/imagenes/scarlett.jpg"), "22/11/1984", "New York, EE.UU", 206);
        crudPerson.crearArtista("Kyle", "Eastwood", new File("./src/frontera/imagenes/kyle.jpg"), "19/05/1968", "Los Angeles, EE.UU", 300);
        crudPerson.crearArtista("Federico", "Jusid", new File("./src/frontera/imagenes/jusid.jpg"), "04/03/1973", "Buenos Aires, Argentina", 301);
        crudPerson.crearArtista("alan", "Silvestri", new File("./src/frontera/imagenes/silvestri.jpg"), "26/05/1950", "New York, EE.UU", 302);
        
        Director a = crudPerson.TraerDirector("Clint");
        Actor b = crudPerson.TraerActor("Clint");
        Actor c = crudPerson.TraerActor("Bee");
        ArrayList<Actor> actores = new ArrayList<Actor>();
        actores.add(c);
        actores.add(b);
        
        Director aa = crudPerson.TraerDirector("Juan Jose");
        Actor bb = crudPerson.TraerActor("Ricardo");
        Actor cc = crudPerson.TraerActor("Soledad");
        ArrayList<Actor> actoresb = new ArrayList<Actor>();
        actoresb.add(bb);
        actoresb.add(cc);
        
        Director aaa = crudPerson.TraerDirector("Joss");
        Actor bbb = crudPerson.TraerActor("robert");
        Actor ccc = crudPerson.TraerActor("Chris");
        Actor ddd = crudPerson.TraerActor("Scarlett");
        ArrayList<Actor> actoresbc = new ArrayList<Actor>();
        actoresbc.add(bbb);
        actoresbc.add(ccc);
        actoresbc.add(ddd);
        
        
        crudMovie.CrearMovie(2008, new File("./src/frontera/imagenes/gran_torino.jpg"), "Gran torino hmong", "Drama", 8.5, 116.0, true, true, "Gran Torino", a, actores);
        crudMovie.CrearMovie(2009, new File("./src/frontera/imagenes/secreto_ojos.jpg"), "el secreto ojos oscar darin", "Suspenso", 10.0, 127.0, false, true, "El Secreto de sus Ojos", aa, actoresb);
        crudMovie.CrearMovie(2012, new File("./src/frontera/imagenes/vengadores.jpg"), "vengadores, iron man, hulk", "Ciencia Ficcion", 13.0, 143.0, false, true, "Los Vengadores", aaa, actoresbc);
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel PanelP;
    private javax.swing.JButton buscarBT;
    private javax.swing.JTextField buscarTF;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JSeparator jSeparator1;
    // End of variables declaration//GEN-END:variables
}
